import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MaterialApp(
        home: MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('自动适配屏幕旋转方向'),
      ),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        child: Flex(
          direction:
              MediaQuery.of(context).orientation != Orientation.landscape //横向
                  ? Axis.vertical
                  : Axis.horizontal,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            ...List.generate(
              5,
              (index) => Container(
                width: 50,
                height: 50,
                color: Colors.blue,
              ),
            )
          ],
        ),
      ),
    );
  }
}
